package com.qdsg.modulesihealsdk;

import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;

import androidx.appcompat.app.AppCompatActivity;

import com.qdsg.modulesihealsdk.camera.CameraCallback;
import com.qdsg.modulesihealsdk.camera.CameraUtils;
import com.qdsg.modulesihealsdk.camera.PreViewImageCallback;
import com.qdsg.modulesihealsdk.deCard.InitDeviceCallback;
import com.qdsg.modulesihealsdk.deCard.QRCodeCallback;
import com.qdsg.modulesihealsdk.deCard.ReadCardUtils;
import com.qdsg.modulesihealsdk.deCard.ReadCardUtilsCallback;
import com.qdsg.modulesihealsdk.detectStrategy.control.DetectFactory;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.bloodFatStrategy.BloodFatCallback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.Spo2Strategy.Spo2Callback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.Spo2Strategy.Spo2Strategy;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.bpStrategy.BpCallback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.uaStrategy.UaCallback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.bfStrategy.BfCallback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.bfStrategy.BfStrategy;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.gluStrategy.GluCallback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.gluStrategy.GluStrategy;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.hwbmiStrategy.HwBmiCallback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.hbStrategy.HbCallback;
import com.qdsg.modulesihealsdk.detectStrategy.strategy.tStrategy.TCallback;
import com.qdsg.modulesihealsdk.ecg12.ECG12Callback;
import com.qdsg.modulesihealsdk.ecg12.ECG12Utils;
import com.qdsg.modulesihealsdk.utils.AudioMngHelper;
import com.qdsg.modulesihealsdk.utils.SihealSdkConstant;
import com.qdsg.modulesihealsdk.utils.SihealUtil;
import com.qdsg.modulesihealsdk.utils.SystemTTS;

/**
 * @Description 新海sdk封装后对外暴露接口的类
 * @Author WuJianFeng
 * @Date 2022/11/21 9:36
 */
public class SihealSdkUtils {


    /**
     * 体温测量
     */
    public static void detectT(Context context, TCallback strategyCallback){
        DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_T).dealDetect(context, strategyCallback);
    }

    /**
     * 血氧/脉率测量
     */
    public static void detectSpo2(Context context, int detectType, Spo2Callback spo2Callback){
        ((Spo2Strategy)DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_SPO2)).setDetectType(detectType).dealDetect(context, spo2Callback);
    }

    /**
     * 血尿酸测量
     */
    public static void detectUA(Context context, UaCallback uaCallback){
        DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_UA).dealDetect(context, uaCallback);
    }

    /**
     * 血脂测量
     */
    public static void detectBloodFat(Context context, BloodFatCallback bloodFatCallback){
        DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_bloodFat).dealDetect(context, bloodFatCallback);
    }

    /**
     * 身高体重
     */
    public static void detectHWBMI(Context context, HwBmiCallback heightWeightCallback){
        DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_HWBMI).dealDetect(context, heightWeightCallback);

    }

    /**
     * 体脂
     */
    public static void detectBF(Context context, int age, String gender, BfCallback BFCallback){
        BfStrategy bfStrategy = (BfStrategy)DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_BF);
        bfStrategy
                .initData(age, SihealUtil.transGenderToInt(gender))
                .dealDetect(context, BFCallback);
    }

    /**
     * 血红蛋白测量
     */
    public static void detectHB(Context context, HbCallback hbCallback){
        DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_HB).dealDetect(context, hbCallback);
    }

    /**
     * 血压测量
     */
    public static void detectBP(Context context, BpCallback bpCallback){
        DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_BP).dealDetect(context, bpCallback);

    }

    /**
     * 血糖
     */
    public static void detectGlu(Context context,
                                 String dinnerTime,
                                 String userName,
                                 String birthday,
                                 String userGender,
                                 String height,
                                 String weight,
                                 String diabetes,
                                 String fpg,
                                 GluCallback gluCallback){

        GluStrategy gluStrategy = (GluStrategy)DetectFactory.getInstance().getDetectStrategy(SihealSdkConstant.channelID_glu);
        gluStrategy.initData(dinnerTime,userName, birthday, userGender, height, weight, diabetes, fpg).dealDetect(context, gluCallback);

    }


    /**
     * 停止线程
     */
    public static void stopThread(){
        DetectFactory.getInstance().stopThread();
    }
    /**
     * 回收资源
     */
    public static void clear(){
        DetectFactory.getInstance().clear();
    }

    /**
     * 初始化
     * 需要在Activity中初始化
     */
    public static void initDevice(Context context, InitDeviceCallback initDeviceCallback) {
        ReadCardUtils.initDevice(context,initDeviceCallback);
    }

    /**
     * 身份证读取
     */
    public static void readIdCard(Activity activity, ReadCardUtilsCallback readCardUtilsCallback){
        ReadCardUtils.readIdCard(activity,readCardUtilsCallback);
    }

    /**
     * 读取社保卡
     */
    public static void readSocialSecurityCard(Activity activity, ReadCardUtilsCallback readCardUtilsCallback){
        ReadCardUtils.readSocialSecurityCard(activity,readCardUtilsCallback);
    }

    /**
     * 扫描二维码
     */
    public static void scanQRCode(QRCodeCallback qrCodeCallback){
        ReadCardUtils.startReadCard(qrCodeCallback);
    }

    /**
     * 停止扫描二维码
     */
    public static void scanQRCodeStop(){
        ReadCardUtils.scanQRCodeStop();
    }

    /**
     * 语音播报
     */
    public static void playTTS(String TTSStr){
        SystemTTS.getInstance().stopSpeak();
        SystemTTS.getInstance().playText(TTSStr);
    }

    /**
     * 停止播放语音
     */
    public static void stopTTS(){
        SystemTTS.getInstance().stopSpeak();
    }

    /**
     * 初始化语音
     */
    public static void initTTS(){
        try {
            SystemTTS.getInstance();
        } catch (Exception e){
        }
    }

    /**
     * 语音控制
     * Activity的context
     */
    public static void AudioManager(Context context,int value){
        AudioMngHelper.getInstance(context).setVoice100(value);
    }

    /**
     * 获取音量值
     * Activity的context
     */
    public static int getAudioValue(Context context){
        return AudioMngHelper.getInstance(context).get100CurrentVolume();
    }

    /**
     * 拍照
     */
    public static void capture(Camera.PictureCallback pictureCallback){
        CameraUtils.getInstance(null).capture(pictureCallback);
    }

    /**
     * 开启摄像头
     */
    public static void openCamera(CameraCallback cameraCallback){
        CameraUtils.getInstance(cameraCallback).openCamera();
    }

    /**
     * 关闭摄像头
     */
    public static void closeCamera(){
        CameraUtils.getInstance(null).closeCamera();
    }

    /**
     * 判断版本
     */
    public static Boolean compareEcg12Version(){
        return ECG12Utils.getInstance().oldVersion.equals(ECG12Utils.getInstance().versionName);
    }

    /**
     * 十二导心电图
     */
    public static void detectEcg12(Activity activity, ECG12Callback ECG12Callback){
        ECG12Utils.getInstance().electrocaRdio(activity, ECG12Callback);
    }

    /**
     * 设置增益
     */
    public static void setGain(int gain){
        ECG12Utils.getInstance().setGain(gain);
    }

    /**
     * 获取增益
     */
    public static int getGain(){
        return ECG12Utils.getInstance().getGain();
    }

    /**
     * 设置走速
     */
    public static void setSpeed(int speed){
        ECG12Utils.getInstance().setSpeed(speed);
    }

    /**
     * 获取走速
     */
    public static int getSpeed(){
        return ECG12Utils.getInstance().getSpeed();
    }

    /**
     * 设置滤波
     */
    public static void setFiler(int filer){
        ECG12Utils.getInstance().setFiler(filer);
    }

    /**
     * 获取滤波
     */
    public static int getFiler(){
        return ECG12Utils.getInstance().getFiler();
    }

    /**
     * 清除关闭心电图
     */
    public static void closeEcg12(){
        ECG12Utils.getInstance().closeElectrocardio();
    }

    /**
     * 人脸识别
     */
    public static void getPreViewImage(PreViewImageCallback preViewImageCallback){
        CameraUtils.getInstance(null).getPreViewImage(preViewImageCallback);
    }
    /**
     *
     */
    public static SurfaceHolder.Callback getSurfaceCallback(){
        return CameraUtils.getInstance(null).mSurfaceCallback;
    }

}
